%
%
%
function [ Markers, TopologyInfo ] = loadANM( FullFileName )

% function [ Markers, TopologyInfo ] = loadANM( FullFileName )

% Markers = [][][];
% TopologyInfo = [];


fid=fopen(FullFileName,'rb');

% tFlag denotes Topology information.
tFlag = fread(fid, 1, 'char'); % 'T'
dtFlag = fread(fid, 1, 'int32'); % 3
numFaces = fread(fid, 1, 'int32');

TopologyInfo = zeros(1,numFaces*3);
TopologyInfo = fread(fid, size(TopologyInfo, 2), 'int32');
TopologyInfo = reshape(TopologyInfo, [3 numFaces]);
TopologyInfo = TopologyInfo';



numFrames = 0;
% gFlag denotes Geometry information.
gFlag = fread(fid, 1, 'char'); % 'P'

    while gFlag==80||gFlag==81
        dgFlag = fread(fid, 1, 'int32'); % 3
        numVerts = fread(fid, 1, 'int32');

        geometryInfo = zeros(1,numVerts*3);
        geometryInfo = fread(fid, size(geometryInfo, 2), 'float');

        if gFlag==80
%             geometryInfo = reshape(geometryInfo, [3 numVerts]);
            geometryInfo = geometryInfo';
            numFrames = numFrames+1;
            Markers(numFrames,:,:) = geometryInfo;
        end
        
        if gFlag==81
            gFlag = fread(fid, 1, 'char'); % 0x00
        end%if
        
        gFlag = fread(fid, 1, 'char'); % 'P'
%         char(gFlag)
    end%while
  
end % function